﻿using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Controls.Renderers.Ios
{
    public abstract class ControlRenderer<TControl, TRenderer> : IControlRenderer<TControl, TRenderer> 
        where TControl : Control<TControl, TRenderer>
        where TRenderer : class, IControlRenderer<TControl, TRenderer>
    {
        //#region Properties

        //private TControl _control;

        //public TControl Control
        //{
        //    get { return _control; }
        //    set { _control = value; }
        //}

        //#endregion Properties

        #region Methods

        public void RenderUiXmlBegin(TControl control, CodeWriter writer)
        {
            if (control != null)
            {
                OnRenderUiXmlBegin(control, writer);
            }
        }

        public void RenderUiXml(TControl control, CodeWriter writer)
        {
            if (control != null)
            {
                OnRenderUiXmlBegin(control, writer);
                OnRenderUiXmlContent(control, writer);

                //OnRenderUiXmlChildControls(control, writer);
                OnRenderUiXmlEnd(control, writer);
            }
        }

        public void RenderUiXmlEnd(TControl control, CodeWriter writer)
        {
            if (control != null)
            {
                OnRenderUiXmlEnd(control, writer);
            }
        }

        protected virtual void OnRenderUiXmlContent(TControl control, CodeWriter writer)
        {
        }

        protected virtual void OnRenderUiXmlBegin(TControl control, CodeWriter writer)
        {
        }

        protected virtual void OnRenderUiXmlEnd(TControl control, CodeWriter writer)
        {
        }

        //public virtual void OnRenderUiXmlChildControls(TControl control, CodeWriter writer)
        //{
        //}

        public void RenderUiCode(TControl control, CodeWriter writer)
        {
            OnRenderViewModelCs(control, writer);
        }

        protected virtual void OnRenderViewModelCs(TControl control, CodeWriter writer)
        {
        }

        protected virtual string GetRenderedUid(TControl control)
        {
            return control.Uid;
        }

        #endregion Methods
    }
}